package com.stylefeng.guns.rest.modular.App.service.impl;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.stylefeng.guns.core.model.CommonKeyValue;
import com.stylefeng.guns.core.model.Pager;
import com.stylefeng.guns.rest.modular.App.dao.OrderNoteDictMapper;
import com.stylefeng.guns.rest.modular.App.model.OrderNoteDict;
import com.stylefeng.guns.rest.modular.App.service.IOrderNoteDictService;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.toolkit.IdWorker;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**

 * 订单备注字典 Service 实现 
 * @author sasazaixian
 * @Date 2018-12-25 10:44
 */
@Service
public class OrderNoteDictServiceImpl extends ServiceImpl<OrderNoteDictMapper,OrderNoteDict> implements IOrderNoteDictService {

    @Resource
    private OrderNoteDictMapper orderNoteDictMapper;

    /**
     * 删除订单备注字典
     * @param orderNoteDict
     * @return     
     */
    @Transactional
    public int deleteOrderNoteDict(OrderNoteDict orderNoteDict,String token)throws Exception{
        if(orderNoteDict==null ){
            throw new RuntimeException("参数不全！");
        }
        return this.orderNoteDictMapper.deleteOrderNoteDict(orderNoteDict);
    }
    /**
     * 批量删除订单备注字典
     * @param ids 主键ID数组
     * @return 
     */
    @Transactional
    public int deleteBatchOrderNoteDict(String[] ids,String token)throws Exception{
        return this.orderNoteDictMapper.deleteBatchOrderNoteDict(ids);
    }
    /**
     * 查询订单备注字典列表
     * @param orderNoteDict 订单备注字典对象
     * @return
     */
    public List<OrderNoteDict> selectListOrderNoteDict(OrderNoteDict orderNoteDict,String token)throws Exception{
        return  this.orderNoteDictMapper.selectListOrderNoteDict(orderNoteDict);
    }
    /**
	 * 分页查询订单备注字典列表
     * @param pager 分页对象
     * @return
     */     
    public  Map pageListOrderNoteDict(Pager pager,String token) throws Exception{
        Page page=new Page(pager.getPageNumber(),pager.getPageSize());
        page.setRecords(orderNoteDictMapper.selectListOrderNoteDict(page,(OrderNoteDict)pager.getObj()));
        List<OrderNoteDict> list = page.getRecords();
        Map mapDate = new HashMap();
        mapDate.put("rows", list);
        mapDate.put("total", page.getTotal());
        mapDate.put("page", page.getCurrent());
        mapDate.put("pageCount", page.getPages());
        return mapDate;
    }
    /**
     * 同一个事务 互斥锁查询
     * @param orderNoteDict 订单备注字典对象
     * @return 
     */
    public  List<OrderNoteDict> selectListOrderNoteDictForUpdate(OrderNoteDict orderNoteDict)throws Exception{
        return  this.orderNoteDictMapper.selectListOrderNoteDictForUpdate(orderNoteDict);
    }
    /**
     * 通过主键id查询的订单备注字典列表
     * @param id 主键id
     * @return     
     */
    public  OrderNoteDict findOrderNoteDictById(String id,String token)throws Exception{
        return  this.orderNoteDictMapper.findOrderNoteDictById(id);
    }

    /**
     * 新增订单备注字典数据
     * @param orderNoteDict  订单备注字典对象
     * @return
     */
    @Transactional
    public int insertOrderNoteDict(OrderNoteDict orderNoteDict,String token) throws Exception { 
        if(orderNoteDict!=null && (orderNoteDict.getOndId()==null || orderNoteDict.getOndId().trim().length()<10)){
            orderNoteDict.setOndId(IdWorker.get32UUID());
        }  
        return this.orderNoteDictMapper.insertOrderNoteDict(orderNoteDict);
    }
    
    /**
     * 更新订单备注字典数据
     * @param orderNoteDict 订单备注字典对象
     * @return     
     */
    @Transactional
    public int updateOrderNoteDict(OrderNoteDict orderNoteDict,String token) throws Exception {     	
        return  this.orderNoteDictMapper.updateOrderNoteDict(orderNoteDict);
    }    

}
